package xyz.o0o0o.demo.HttpClientDemo;

import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class HttpUtil {

	public static void getMethod() throws ClientProtocolException, IOException {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		String baseUrl = "http://www.baidu.com";
		HttpGet get = new HttpGet(baseUrl);
		get.setHeader("aaa", "aa");
		for (Header header : get.getAllHeaders()) {
			System.out.println(header.getName() +":"+header.getValue());
		}
		CloseableHttpResponse response = httpclient.execute(get);
		try {
			System.out.println(EntityUtils.toString(response.getEntity(),"utf-8"));
		} finally {
			response.close();
		}
	}
	
	
	public static void post(){
		CloseableHttpClient httpclient = HttpClients.createDefault();
	}

	public static void main(String[] args) {
		try {
			getMethod();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
